﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;
using System.IO;
using System.Net;
using TDT.Land.Utilities;
using TDT.Land.BusinessLogic;
using System.Text.RegularExpressions;
using TDT.Land.Entity;

namespace TDT.Land.Web.Controllers
{
    public class KimThanh_infoController : BaseController
    {
        //
        // GET: /KimThanh_info/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About_us()
        {
            var ext = AdminRepo.Instance.GetProBuildingByCode("gioi-thieu", UserName);
            ViewBag.Bcontent = ext;
            return View();
        }

        public ActionResult Contact()
        {
            var ext = AdminRepo.Instance.GetProBuildingByCode("lien-he", UserName);
            ViewBag.Bcontent = ext;
            return View();
        }

        public ActionResult news()
        {
            string buidingType = CategoryType.W_NEW_TYPE.ToString();
            List<Pro_Building> lstBuidingTop = AdminRepo.Instance.GetProBuildingByType(buidingType).OrderByDescending(m => m.DateCreate).Take(40).ToList();
            foreach (var itemData in lstBuidingTop)
            {
                itemData.Description = Regex.Replace(itemData.Description, @"<img\s[^>]*>(?:\s*?/>)?", "", RegexOptions.IgnoreCase);
                itemData.Description = Regex.Replace(itemData.Description, @"<(.|\n)*?>", string.Empty);
                int descLength = itemData.Description.Length;
                if (descLength > 350)
                    itemData.Description = itemData.Description.Substring(0, 350) + "...";
            }
            ViewBag.lstNews = lstBuidingTop;
            return View();
        }

        public ActionResult SendMail(string name , string subject,string mail, string phone, string content)
        {
            string statusSent = "01";
            string body = content;
            string fromMail = mail;

            var isSendSuccess = Mailer.SendMail(fromMail, body, subject, name, phone);
            if (isSendSuccess)
                statusSent = "00";

            return Content(statusSent);
        }

    }
}
